﻿using Kingdee.BOS.App.Data;
using Kingdee.BOS.Core.DynamicForm.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Util;
using NS.MaterialChange;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NS
{
    [HotUpdate]
    [Description("抓取网址中的关键信息内容")]
    public class CatchHttpCon : AbstractDynamicFormPlugIn
    {
        public override void DataChanged(DataChangedEventArgs e)
        {
            base.DataChanged(e);
            string F_QZPV_Remark = "";
            F_QZPV_Remark = Convert.ToString(this.Model.GetValue("F_QZPV_Remark"));
            if (F_QZPV_Remark.Contains("spm"))
            {
                int startIndex = F_QZPV_Remark.IndexOf("offer/") + "offer/".Length;
                int endIndex = F_QZPV_Remark.IndexOf(".html", startIndex);
                string productId = "";
                if (startIndex != -1 && endIndex != -1)
                {
                    productId = F_QZPV_Remark.Substring(startIndex, endIndex - startIndex);
                }
                this.Model.SetValue("F_WNEG_Text16", productId);
                this.View.UpdateView("F_WNEG_Text16");
            }
            if (F_QZPV_Remark.Contains("http://detail.m.1688.com/page/index.htm"))
            {
                int startIndex = F_QZPV_Remark.IndexOf("offerId=") + "offerId=".Length;
                string result = F_QZPV_Remark.Substring(startIndex);
                this.Model.SetValue("F_WNEG_Text16", result);
                this.View.UpdateView("F_WNEG_Text16");
            }
            if (F_QZPV_Remark.Contains("https://detail.1688.com/offer/"))
            {
                int startIndex = F_QZPV_Remark.IndexOf("offer/") + "offer/".Length;
                int endIndex = F_QZPV_Remark.IndexOf(".htm", startIndex);
                string productId = "";
                if (startIndex != -1 && endIndex != -1)
                {
                    productId = F_QZPV_Remark.Substring(startIndex, endIndex - startIndex);
                }
                this.Model.SetValue("F_WNEG_Text16", productId);
                this.View.UpdateView("F_WNEG_Text16");
            }
        }
    }
}
